package com.meyou.javascript.rewriter;

public class RewriteEnvirons {

	private static final String GEN_PREFIX = "my_";
	
	private boolean isAsync;
	private String asyncCallbackName;
	private String asyncCallbackParamName;
	private String functionName;
	private String typeId;
	private RewriteTypeEnum type;
	private RewriteRegistry registry = new RewriteRegistry();
	private RewriteIdGen idGen = new RewriteIdGen(GEN_PREFIX);
	
	public RewriteEnvirons(RewriteRegistry registry)
	{
		super();
		
		this.registry = registry;
	}
	
	public String getAsyncCallback()
	{
		return asyncCallbackName;
	}
	
	public void setAsyncCallback(String asyncCallbackName) {
		this.asyncCallbackName = asyncCallbackName;
	}

	public String getAsyncCallbackParam()
	{
		return asyncCallbackParamName;
	}

	public void setAsyncCallbackParam(String asyncCallbackParamName) {
		this.asyncCallbackParamName = asyncCallbackParamName;
	}

	public boolean isAsync() {
		return isAsync;
	}

	public void setAsync(boolean isAsync) {
		this.isAsync = isAsync;
	}

	public String getFunctionName() {
		return functionName;
	}

	public void setFunctionName(String functionName) {
		this.functionName = functionName;
	}

	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	public RewriteTypeEnum getType() {
		return type;
	}

	public void setType(RewriteTypeEnum type) {
		this.type = type;
	}
	
	public boolean needsRewrite(String type, String call)
	{
		try
		{
			return registry.containsEntry(type, call);
		}
		catch(IllegalArgumentException e)
		{
		}
		
		return false;
	}
	
	public String genId()
	{
		return idGen.genId();
	}
	
}
